<script lang="ts">
import {defineComponent, SlotsType, PropType} from 'vue';
import {auth as AuthCheck} from "@/apps/admin/units/auth";

/**
 * 权限验证组件
 */
export default defineComponent({
  name: 'AdminAuth',
  slots: Object as SlotsType<{
    default: {},
    fail: {}
  }>,
  props: {
    sign: {
      type: [String, Array] as PropType<string | string[]>,
      required: true
    },
    mode: {
      type: String as PropType<'AND' | 'OR'>,
      default: 'AND'
    }
  },
  setup(props, {slots}) {
    return () => {
      if (AuthCheck(props.sign, props.mode)) {
        if (slots?.default instanceof Function) {
          return slots?.default({})
        }
      } else if (slots?.fail instanceof Function) {
        return slots?.fail({})
      }
      return null
    }
  }
})
</script>